package com.codeest.geeknews.base;

/**
 * 适用于当Fragment需要拦截返回键
 * Created by admin on 2017/8/28.
 */

public abstract class BackHandledActivity extends SimpleActivity implements IBackHandledInterface {

    private BackHandledFragment mBackHandedFragment;
    private boolean hadIntercept;

    @Override
    public void setSelectedFragment(BackHandledFragment selectedFragment) {
        this.mBackHandedFragment = selectedFragment;
    }

    @Override
    public void onBackPressedSupport() {
        if (mBackHandedFragment == null || !mBackHandedFragment.onBackPressed()) {
            if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
                super.onBackPressedSupport();
            } else {
                getSupportFragmentManager().popBackStack();
            }
        }
    }
}
